<?php global $ubi;?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
	    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>TÙM LUM site</title>
        
		<link href="include/css/style.css" media="screen" rel="stylesheet" type="text/css" />
		<link href="include/css/styles.css" type="text/css" media="all" rel="stylesheet" id="contact-form-7-css" />
        <link href="include/css/site.css" media="screen" type="text/css" rel="stylesheet" />
		<link href="include/css/jquery.wysiwyg.css" type="text/css" rel="stylesheet" />
		<link href="include/css/jquery-ui.css" type="text/css" rel="stylesheet" />
		
		<script language="javascript" src="include/script/jquery-1.4.4.min.js" type="text/javascript"></script>
		<script language="javascript" type="text/javascript" src="include/script/script.js"></script>
		<script language="javascript" type="text/javascript" src="include/script/jquery-ui-1.8.14.custom.min.js"></script>  
		<script language="javascript" type="text/javascript" src="include/script/jquery.wysiwyg.js"></script>
		<script language="javascript" type="text/javascript" src="include/script/script.js"></script>
		
		<script type="text/javascript" language="javascript">
			$(document).ready(function(){
				$('#randomItemProvider').load('index.php?load&view=randomItemProvider');
				$('#blockSignIn').load('index.php?load&view=blockSignIn');
				$('#blockSearch').load('index.php?load&view=blockSearch');
				$('#blockMembers').load('index.php?load&view=blockMembers');
				$('#blockNewestPosts').load('index.php?load&view=blockNewestPosts');
				$('#mainMenu').load('index.php?load&view=menu');
				$('#footer').load('index.php?load&view=footer');
				
				$('#diadiem_input').wysiwyg();

				$('#lnkUpdateAddr').click(function() {				
					$('#dlgUpdateAddr').dialog('open');																
				});
				$('#dlgUpdateAddr').dialog({autoOpen: false, width:'360px'});

				var url = 'index.php?location&action=get';
				var pid = 0;			
				$.post(url, 
					{parentID: pid}, 
					function(xml) {			
						var str1 = $.getXMLStringOf(xml, 'location', '<?php echo $addressModel->getCity()?>');
						if (str1 != '') {
							$('#selCity').html(str1);
							pid = $('#selCity option:selected').val();											
							$.post(url, 
								{parentID: pid}, 
								function(xml) {								
									var str2 = $.getXMLStringOf(xml, 'location', '<?php echo $addressModel->getDistrict()?>');								
									if (str2 != '') {
										$('#selDistrict').html(str2);
										pid = $('#selDistrict option:selected').val();
										$.post(url,
												{parentID: pid},
												function(xml){
													var str3 = $.getXMLStringOf(xml, 'location', '<?php echo $addressModel->getWard()?>');
													$('#selWard').html(str3);
												}
										);
									}
								}
							);
						} 												
					}
				);
				
				$('#frmUpdateAddr').submit(function() {								
					var url = 'index.php?update&type=address';
					
					var id = $('#frmUpdateAddr [name=id]').val();
					var city = $('#selCity').val();
					var district = $('#selDistrict').val();
					var ward = $('#selWard').val();
					var number = $('#frmUpdateAddr [name=txtNumber]').val();
					var street = $('#frmUpdateAddr [name=txtStreet]').val();				
					
					$.post(url,
							{id : id, city : city, district : district, ward : ward, number : number, street : street},
							function(data){							
								if (data == '') {
									alert('Cập nhật địa chỉ không thành công');								
								} else {
									var strAddr = number + ', ' + street + ', ' 
													+ $('#selWard option:selected').text() + ', ' 
													+ $('#selDistrict option:selected').text() + ', ' 
													+ $('#selCity option:selected').text();
									$('#address').html(strAddr);
								}
								$('#dlgUpdateAddr').dialog('close');			
							}); 
					
					return false;
				});

				$('#btnThoatUpdateAddr').click(function(){
					$('#dlgUpdateAddr').dialog('close');
				});					

				$('#selCity').change(function() {
					url = 'index.php?location&action=get';
					var pid = $('#selCity').val(); 
					$.post(url, 
						{parentID: pid}, 
						function(xml) {
							var str = $.getXMLStringOf(xml, 'location');
							$('#selDistrict').html(str);

							var pid = $('#selDistrict').val();
							$.doPostGetLocationList(pid, '#selWard', url);
						}
					);
				});

				$('#selDistrict').change(function() {				
					url = 'index.php?location&action=get';
					var pid = $('#selDistrict').val();
					$.doPostGetLocationList(pid, '#selWard', url);
				});

				$('#selCatProvider1').change(function() {
					pid = $('#selCatProvider1 option:selected').val();
					url = 'index.php?input&action=getCategoryProvider';

					$.doPostGetCategoryList(pid, '#selCatProvider2', url);
				});
				
				$('#lnkAddProviderCategory').click(function() {
					var val = $('#selCatProvider2 option:selected').val();

					var arrCat = [];
					$('input[class=hiddenCatProviderID]').each(function(index) {
						arrCat.push($(this).val());		    
					});
					var ok = true;
					for (var i = 0; i < arrCat.length; i++) {
						if (arrCat[i] == val) {
							ok = false;							
							break;
						}
					}
					
					if (ok) {
						$('#messCat').hide();
						var newRow = '<tr><td>' + $('#selCatProvider1 option:selected').html() + '</td>' 
							+ '<td>' + $('#selCatProvider2 option:selected').html() + '</td>' 
							+ '<td>' + '<input type="button" value="Xóa" onclick="$.removeCat(this)"></td>'
							+ '<td><input type="hidden" class="hiddenCatProviderID" value="' + val + '" /></td>' 
							+'</tr>';
						$('#tblCatProvider tr:last').after(newRow);
						$.getTextFromCategory(val);
					} else {
						$('#messCat').html('Phân loại này đã được chọn. Bạn hãy chọn một phân loại khác !!!');
						$('#messCat').show();
					}
				});

				$('#frmUpdateProvider').submit(function() {
					var str = '';
					if ($('#frmUpdateProvider [name=txtProviderName]').val() == '') {			
						str += 'Bạn chưa nhập tên provider\n';
					}
					if ($('#frmUpdateProvider [name=txtNumber]').val() == '') {
						str += 'Bạn chưa nhập số nhà\n';
					}
					if ($('#frmUpdateProvider [name=txtStreet]').val() == '') {
						str += 'Bạn chưa nhập số nhà\n';
					}				

					if (str != '') {
						alert(str);
						return false;
					}	

					var str = '';
					$('input[class=hiddenCatProviderID]').each(function(index) {
						str += ' ' + $(this).val();		    
					});		
					$('input[name=categoryProviderList][type=hidden]').val(str);

					var answerList = '';
					$('#frmUpdateProvider input[type=radio]').each(function(index) {
						if ($(this).attr('checked')) {
							answerList += $(this).val() + ' ';
						}		    
					});
					$('input[name=answerList]').val(answerList);
					
					return true;
				});

				var arrCat = [];
				var strArrCat = '<?php echo $providerModel->getCategoryList()?>';
				arrCat = strArrCat.split(' ');
				for (var i = 0; i < arrCat.length; i++) {
					$.getTextFromCategory(arrCat[i]);
				}
			});

			var arrAnswer = [];
			var strAnswerList = '<?php echo $providerModel->getAnswerList()?>';
			arrAnswer = strAnswerList.split(' ');
			
			$.extend({
				removeCat:function(tag) {
					$.removeRow(tag);
					var val = $(tag).parent().parent().find('input[type=hidden]').val();
					$('#cat' + val).remove();
				},
				getTextFromCategory:function(val) {
					var url = 'index.php?input&action=getCategoryProviderQuestion';
					$.post(url, {'cat' : val}, function(data){
						var str = '<div id="cat' + val + '">' + $.getStringFromXMLQuestions(data) + '</div>';							
						$('#blockDanhGia').append(str);

						for (var i = 0; i < arrAnswer.length; i++) {
							var question_answer = arrAnswer[i].split('-');
							$('input[name=' + question_answer[0] + ']').
								filter("[value="+question_answer[0]+"-"+question_answer[1]+"]").
								attr("checked","checked");
						}
					});
				}
			});
		</script>
	</head>
    
    <body id="cookoffboard" class="home blog">
		<div id="corners">			
			<div class="header" id="main-head">
				<div id="hdr-info">
                	<div style="float:left">
                        <img id="logo" src="include/imgs/logo4.png" alt="The Cook-Off Board" width="235px" />
                        <p id="desc">Tùm Lum, Tả Pí Lù, chia sẻ tất cả ở đây</p>
                    </div>
                    <div class="nav">
                        <div id="mainMenu"></div>
                        <div style="clear:both"></div>
                    </div>
				</div>             
			</div> <!--end header-->
            
			<div class="polaroids">
            	<div class="marginBoxPicCollection" id="randomItemProvider"></div>
			</div> <!--end polaris-->
            
            <div id="container">
				<hr />
                <div class="left">
                    <div class="section" id="content">
                    	<h1>Cập nhật thông tin địa điểm</h1>
                        <form name="frmUpdateProvider" id="frmUpdateProvider" method="post"	action="index.php?provider&action=update">
							<fieldset class="form">
						    	<ul class="frm">
						        	<li class="input">
						            	<label for="name">Tên Địa Điểm <span class="red">*</span></label>
						            	<input type="text" name="txtProviderName" value="<?php echo $providerModel->getProvider()?>" class="txt_full" />
						            </li>
						            <li class="input">
				                    	<label>Địa chỉ</label>
										<span id="address"><?php echo $strAddress?></span>
										<br />
	                                    <label>&nbsp;</label>
	                                    <span class="note"><a href="#" id="lnkUpdateAddr">Cập nhật địa chỉ</a></span>                        	                        
				                    </li>   
				                    <li class="input">        
						            	<label>Website</label>
										<input type="text" name="txtWebsite" value="<?php echo $providerModel->getWebsite()?>" />
						            </li>
						            <li class="input">
						            	<label>ĐT di động</label>
						                <input type="text" name="txtCellphone" value="<?php echo $providerModel->getCellphone()?>" />
						            </li>
`						            <li class="input">
						            	<label>ĐT cố định</label>
						                <input type="text" name="txtTelephone" value="<?php echo $providerModel->getTelephone()?>" />
						            </li>
						            <li class="input">
				                    	<label>Phân loại</label>
				                    	<div style="margin-left:100px;">
				                    		<div>
				                    			<table id="tblCatProvider">
							                		<tr>						                			
							                			<td style="text-wrap:normal" colspan="3">
							                				<span class="red" id="messCat">
							                					
							                				</span>
							                			</td>						                			
							                		</tr>
							                    	<tr>
							                        	<td>
							                                <select name="selCatProvider1" id="selCatProvider1">
							                                	<?php                 
							                                	    for ($i = 0; $i < count($arrCatProvider1); $i++) {
							                                			$catProvider = $arrCatProvider1[$i];
							                                	?>
							                                	<option value="<?php echo $catProvider->getCategoryID();?>"><?php echo $catProvider->getCategory();?></option>
							                                	<?php 		
							                                		} 
							                                	?>	
							                                </select>
							                            </td>
							                            <td>
							                                <select name="selCatProvider2" id="selCatProvider2">
							                                    <?php
							                                		$catProvider =  $arrCatProvider2[0];
							                                	?>
							                                	<option selected="selected" value="<?php echo $catProvider->getCategoryID();?>"><?php echo $catProvider->getCategory();?></option>
							                                	<?php                 
							                                	    for ($i = 1; $i < count($arrCatProvider2); $i++) {
							                                			$catProvider = $arrCatProvider2[$i];                                	
							                                	?>
							                                	<option value="<?php echo $catProvider->getCategoryID();?>"><?php echo $catProvider->getCategory();?></option>
							                                	<?php 		
							                                		} 
							                                	?>                            	
								                            </select>
							                            </td>
							                            <td><input type="button" id="lnkAddProviderCategory" value="Thêm" /></td>                            
													</tr>
													<?php
														for ($i = 0; $i < count($arrCatParent); $i++) {
													?>
														<tr>
															<td><?php echo $arrCatParent[$i]->getCategory()?></td>
															<td><?php echo $arrCat[$i]->getCategory()?></td>
															<td><input type="button" value="Xóa" onclick="$.removeCat(this)" /></td>
															<td><input type="hidden" class="hiddenCatProviderID" value="<?php echo $arrCat[$i]->getCategoryID()?>" /></td>
														</tr>	
													<?php 		
														} 
													?>                                		                                		
												</table>
												<input type="hidden" name="answerList" />
				                    		</div>                        
					                    </div>
				                    </li>                    
				                    <li class="input">
				                    	<label>Đánh giá</label>	     
				                    	<div style="display:inline-block;" id="blockDanhGia"></div>                   
				                    </li>
				                    <li class="input">
						            	<label for="mota">Mô Tả</label>
						            	<div></div>
						            </li>
								</ul>
								
								<div style="clear:both"></div>		            				                
				        		<textarea id="diadiem_input" class="textarea_input" rows="10" cols="75" name="txtProviderDes">
					                <?php echo $providerModel->getDescription()?>	
					            </textarea>
							    <br />   			                	
								
								<input type="hidden" name="categoryProviderList" />
								<input type="hidden" name="answerList" value="<?php echo $providerModel->getAnswerList()?>" />                	            
								<input type="hidden" name="providerID" value="<?php echo $providerModel->getProviderID()?>" />		        		        
					            <input type="submit" value="Cập nhật" />
							</fieldset>						    
						</form>
						<div class="clear"></div>                     
                    </div>  <!--end section -->
            	</div> <!-- end left -->        
                <div class="right">
        			<div class="aside">
                        <ul class="blockRightSide">	
                            <li class="blockRight" id="blockSignIn"></li>
                            <li class="blockRight" id="blockSearch"></li>                                            
                            <li class="blockRight" id="blockMembers"></li>
                            <li class="blockRight" id="blockNewestPosts"></li>                          
                        </ul>
                    </div>        
                </div> <!--end right-->
			</div> <!--end container-->		
            
           <div id="footer" class="footer clearfix"></div>
		</div>
		
		<div id="dlgUpdateAddr" title="Cập nhật địa chỉ">
			<form name="frmUpdateAddr" id="frmUpdateAddr">		
				<ol>
					<li class="input">
						<label>Thành phố</label> 
						<select id="selCity" name="selCity" class="txtAddr">                                    	
		                </select>
					</li>
					<li class="input">
		            	<label for="quan">Quận/Huyện</label>
		                <select id="selDistrict" name="selDistrict" class="txtAddr">
		                </select>
					</li>
		            <li class="input">
		            	<label for="phuong">Phường/Xã</label>
		                <select id="selWard" name="selWard" class="txtAddr">
		                </select>
					</li>        
		            <li class="input">  
		            	<label for="sonha">Số Nhà</label>
		                <input type="text" class="txt_short" name="txtNumber" class="txtAddr" value="<?php echo $addressModel->getNumber()?>"/>
		            </li>
		            <li class="input">        
		            	<label for="duong">Đường</label>
						<input type="text" name="txtStreet" class="txtAddr" value="<?php echo $addressModel->getStreet()?>"/>
		            </li>
				</ol>		
				<input type="hidden" value="<?php echo $addressModel->getAddressID()?>" name="id" />
				<input type="submit" value="Cập nhật" />
				<input type="button" value="Thoát" id="btnThoatUpdateAddr" />
			</form>
		</div>
	</body>
</html>